package com.hl.web.fore;

import com.hl.pojo.PublicWelfare;
import com.hl.service.PublicWelfareService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/publicWelfare")
public class PublicWelfareController {
    @Autowired
    private PublicWelfareService service;

    @PostMapping("/add")
    public ResultEntity add(@RequestBody PublicWelfare publicWelfare) {
        Date date = new Date();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        publicWelfare.setCreateTime(s.format(date));
        service.add(publicWelfare);
        return ResultEntity.ok();
    }

    @GetMapping("/findAll")
    public ResultEntity findAll() {
        return ResultEntity.ok(service.findAll());
    }


    @GetMapping("/del")
    public ResultEntity del(Integer id) {
        service.del(id);
        return ResultEntity.ok();
    }


    @GetMapping("/findById")
    public ResultEntity findById(Integer id) {
        return ResultEntity.ok(service.findById(id));
    }


    @PostMapping("/update")
    public ResultEntity update(@RequestBody PublicWelfare publicWelfare) {
        service.update(publicWelfare);
        return ResultEntity.ok();
    }

}
